import torch
import cv2
import numpy as np
from function.viewImage import drawPoints


def image_norm(image):
    image = (image / 255.0 - 0.5) / 0.5
    return image

def image_de_norm(image):
    image = (image * 0.5 + 0.5) * 255.0
    return image

def showIMG_in_train(data):
    cv2.namedWindow("ShowImage", 0)
    cv2.moveWindow("ShowImage", 100, 100)
    cv2.resizeWindow("ShowImage", 800,800)
    path, images, landmark = data[0], data[1], data[2]

    for id, img in enumerate(images):
        lm = landmark[id]
        img_h, img_w, _ = img.shape
        lm = lm * torch.tensor([img_w, img_h], dtype=torch.float)
        lm = lm.numpy().tolist()
        img = (img * 0.5 + 0.5) * 255.0
        img = img.numpy().astype(np.uint8)
        img = drawPoints(img, lm, color=(0,255,0), idColor=(0,0,255) ,drawID=False)
        cv2.imshow("ShowImage", img)
        cv2.waitKey(0)
